<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>

    </style>
</head>
<body>
<div id="app">
    <el-page-header
            style="background-color: #0095d7;color: white;
                    line-height: 60px"
            @back="goBack" content="添加用户">
    </el-page-header>
    用户：<input type="text" v-model="user.username"       placeholder="用户名"> <br/>
    密码：<input type="text" v-model="user.password"   placeholder="密码"><br/>
    昵称：<input type="text" v-model="user.nickname"    placeholder="昵称"><br/>

    <el-button type="success" @click="insert()">添加用户</el-button>

</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                user:{
                    username:"",
                    password:"",
                    nickname:"",
                }
            }
        },
        methods: {
            goBack(){
                history.back();//返回上一页面
            },
            insert(){
                if (v.user.username=="" || v.user.username.trim() == ""){
                    v.$message("请输入用户名!");
                    return;
                }
                if (v.user.password=="" || v.user.password.trim() == ""){
                    v.$message("请输入密码!");
                    return;
                }
                if (v.user.nickname=="" || v.user.nickname.trim() == ""){
                    v.$message("请输入昵称!");
                    return;
                }
                axios.post("/user/insert",v.user).then(function () {
                    //返回后台管理页面
                    location.href="/admin.html";
                })

            }
        }
    })
</script>
</html>